package com.ruoyi.web.controller;


import com.github.pagehelper.PageHelper;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.QueryDict;
import com.ruoyi.common.core.domain.entity.SysDic;
import com.ruoyi.common.core.domain.entity.SysMenu;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.service.ISysDicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author linxz
 * @since 2024-12-25
 */
@RestController
@RequestMapping("/sysDic")
public class SysDicController extends BaseController {

    @Autowired
    private ISysDicService service;

    @PostMapping("/list")
    public TableDataInfo list(@RequestBody QueryDict query) {
        // 根据参数写 limit 查询语句
        PageHelper.startPage(query.getPageNum(), query.getPageSize());
        List<SysDic> dicList = service.fetchList(query);
        return getDataTable(dicList);

    }

    @PostMapping("/add")
    public AjaxResult add(@RequestBody SysDic sysDic){
        return toAjax(service.add(sysDic));
    }
    @PostMapping("/update")
    public AjaxResult update(@RequestBody SysDic sysDic){
        return toAjax(service.update(sysDic));

    }
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody SysDic sysDic){
        return toAjax(service.delete(sysDic.getId()));
    }

}
